package com.ourteam.workspace.dao.impl;

import com.ourteam.workspace.dao.IWorkspaceScmConfigDAO;
import com.ourteam.workspace.dao.WorkspaceScmConfig;
import com.ourteam.workspace.dao.WorkspaceScmConfigDAOQueryBean;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import net.dao.AbstractSpringDAO;
import net.dao.DataAccessObjectHelper;
import org.apache.commons.beanutils.PropertyUtils;
import org.springframework.jdbc.core.RowMapper;

/**
 * Template Name : DAO服务对象 Template Version : 1 Template Last Modfiy Date : Fri Nov 17 11:00:11 CST
 * 2017 Auto Generate Date : 2018-11-30 18:42:33 Warning ! This file will be overwrite when
 * regenerate !
 */
public class AbstractWorkspaceScmConfigDAOJdbcImpl extends AbstractSpringDAO
    implements IWorkspaceScmConfigDAO {

  public static final String[] ENTITY_FIELDS =
      new String[] {
        Id,
        WorkspaceId,
        ScmType,
        Protocol,
        HostName,
        HostPort,
        Module,
        ScmUser,
        ScmPassword,
        Status,
        Remarks,
        Branch,
        Label
      };

  public static final String[] ENTITY_PROPERTIES =
      new String[] {
        _DataObjectProperty.Id,
        _DataObjectProperty.WorkspaceId,
        _DataObjectProperty.ScmType,
        _DataObjectProperty.Protocol,
        _DataObjectProperty.HostName,
        _DataObjectProperty.HostPort,
        _DataObjectProperty.Module,
        _DataObjectProperty.ScmUser,
        _DataObjectProperty.ScmPassword,
        _DataObjectProperty.Status,
        _DataObjectProperty.Remarks,
        _DataObjectProperty.Branch,
        _DataObjectProperty.Label
      };

  public static final String[] ENTITY_PK_FIELDS = new String[] {Id};

  public static final String[] ENTITY_AUTO_GEN_PK_FIELDS = new String[] {Id};

  public static final String[] ENTITY_UNIQUE_FIELDS = new String[] {};

  private static String relatedJoinSQL = null;

  private static String basicFilterSQL = null;

  private DataAccessObjectHelper<WorkspaceScmConfig, WorkspaceScmConfigDAOQueryBean> daoHelper;

  public AbstractWorkspaceScmConfigDAOJdbcImpl() {
    super();
    daoHelper =
        new DataAccessObjectHelper<WorkspaceScmConfig, WorkspaceScmConfigDAOQueryBean>(this);
  }

  protected String getEntityName() {
    return EntityName;
  }

  protected String[] getEntityFields() {
    return ENTITY_FIELDS;
  }

  protected String[] getEntityProperties() {
    return ENTITY_PROPERTIES;
  }

  protected String[] getEntityPKFields() {
    return ENTITY_PK_FIELDS;
  }

  protected String[] getEntityAutoGenPKFields() {
    return ENTITY_AUTO_GEN_PK_FIELDS;
  }

  protected String[] getEntityUniqueFields() {
    return ENTITY_UNIQUE_FIELDS;
  }

  protected String getBaiscQueryFilter() {

    if (basicFilterSQL == null) {
      StringBuffer basicFilterSQLbuffer = new StringBuffer();

      basicFilterSQL = basicFilterSQLbuffer.toString();
    }

    return basicFilterSQL;
  }

  protected String getRelatedJoinSQL() {

    if (relatedJoinSQL == null) {
      StringBuffer relatedJoinSQLBuffer = new StringBuffer();

      relatedJoinSQL = relatedJoinSQLBuffer.toString();
    }

    return relatedJoinSQL;
  }

  /**
   * Check Data Unique
   *
   * @param aWorkspaceScmConfig
   * @throws Exception
   */
  public boolean checkIsUnique(WorkspaceScmConfig aWorkspaceScmConfig) throws Exception {

    if (aWorkspaceScmConfig == null) {
      return true;
    }

    List valueList = new ArrayList();

    List pkValueList = new ArrayList();

    pkValueList.add(aWorkspaceScmConfig.getId());

    return isUnique(
        valueList.toArray(new Object[valueList.size()]),
        pkValueList.toArray(new Object[pkValueList.size()]));
  }

  /**
   * Insert Data
   *
   * @param aWorkspaceScmConfig
   * @throws Exception
   */
  public void insert(WorkspaceScmConfig aWorkspaceScmConfig) throws Exception {

    super.doInsert(aWorkspaceScmConfig);
  }

  /**
   * Batch Insert Datas
   *
   * @param aWorkspaceScmConfig
   * @throws Exception
   */
  public void batchInsert(WorkspaceScmConfig[] aWorkspaceScmConfigs) throws Exception {

    super.doBatchInsert(aWorkspaceScmConfigs);
  }

  /**
   * Delete Data
   *
   * @param final long id *
   * @throws Exception
   */
  public void delete(final long id) throws Exception {

    super.doDeleteById(new Object[] {new Long(id)});
  }

  /**
   * Delete Datas
   *
   * @param queryBean
   * @throws Exception
   */
  public void delete(WorkspaceScmConfigDAOQueryBean queryBean) throws Exception {

    super.doDeleteByQuery(queryBean);
  }

  public void delete(WorkspaceScmConfig aWorkspaceScmConfig) throws Exception {

    delete(aWorkspaceScmConfig.getId());
  }

  /**
   * Update Data Selective
   *
   * @param aWorkspaceScmConfig
   * @throws Exception
   */
  public void update(WorkspaceScmConfig aWorkspaceScmConfig) throws Exception {

    if (aWorkspaceScmConfig.getId() == 0) {
      throw new Exception("Can not update object data whith out primary key value");
    }

    super.doUpdate(aWorkspaceScmConfig);

    WorkspaceScmConfig tempObj = findById(aWorkspaceScmConfig.getId());

    if (tempObj != null) {
      PropertyUtils.copyProperties(aWorkspaceScmConfig, tempObj);
    }
  }

  /**
   * Batch Update Datas
   *
   * @param aWorkspaceScmConfigs[]
   * @throws Exception
   */
  public void batchUpdate(WorkspaceScmConfig[] aWorkspaceScmConfigs) throws Exception {

    super.doBatchUpdate(aWorkspaceScmConfigs);
  }

  /**
   * Update Data By Condictions
   *
   * @param aWorkspaceScmConfig
   * @param aValueCriteria
   * @param aTransaction
   * @throws Exception
   */
  public void update(
      WorkspaceScmConfig aWorkspaceScmConfig, WorkspaceScmConfigDAOQueryBean aQueryBean)
      throws Exception {

    super.doUpdateByQuery(aWorkspaceScmConfig, aQueryBean);
  }

  /**
   * Update Data By Condictions
   *
   * @param aQueryBean
   * @throws Exception
   */
  public void update(WorkspaceScmConfigDAOQueryBean aQueryBean) throws Exception {
    super.doUpdateByQuery(aQueryBean);
  }

  protected void checkNullValue(WorkspaceScmConfig aWorkspaceScmConfig) throws Exception {

    if (aWorkspaceScmConfig.getScmType() == null) {
      throw new Exception("The WorkspaceScmConfig.scmType value is not allow NULL");
    }

    if (aWorkspaceScmConfig.getProtocol() == null) {
      throw new Exception("The WorkspaceScmConfig.protocol value is not allow NULL");
    }

    if (aWorkspaceScmConfig.getHostName() == null) {
      throw new Exception("The WorkspaceScmConfig.hostName value is not allow NULL");
    }

    if (aWorkspaceScmConfig.getHostPort() == null) {
      throw new Exception("The WorkspaceScmConfig.hostPort value is not allow NULL");
    }

    if (aWorkspaceScmConfig.getModule() == null) {
      throw new Exception("The WorkspaceScmConfig.module value is not allow NULL");
    }

    if (aWorkspaceScmConfig.getScmUser() == null) {
      throw new Exception("The WorkspaceScmConfig.scmUser value is not allow NULL");
    }

    if (aWorkspaceScmConfig.getScmPassword() == null) {
      throw new Exception("The WorkspaceScmConfig.scmPassword value is not allow NULL");
    }

    if (aWorkspaceScmConfig.getStatus() == null) {
      throw new Exception("The WorkspaceScmConfig.status value is not allow NULL");
    }

    if (aWorkspaceScmConfig.getRemarks() == null) {
      throw new Exception("The WorkspaceScmConfig.remarks value is not allow NULL");
    }

    if (aWorkspaceScmConfig.getBranch() == null) {
      throw new Exception("The WorkspaceScmConfig.branch value is not allow NULL");
    }

    if (aWorkspaceScmConfig.getLabel() == null) {
      throw new Exception("The WorkspaceScmConfig.label value is not allow NULL");
    }
  }

  /**
   * Get Data By ID
   *
   * @param final long id * @return ${businessObject.name}
   * @throws Exception
   */
  public WorkspaceScmConfig findById(final long id) throws Exception {

    WorkspaceScmConfigDAOQueryBean queryBean = new WorkspaceScmConfigDAOQueryBean();

    WorkspaceScmConfigDAOQueryBean.Criteria criteria = queryBean.createCriteria();

    criteria.andIdEqualTo(id);

    // queryBean.setDistinct(true);

    WorkspaceScmConfig[] WorkspaceScmConfigs = query(queryBean);

    if (WorkspaceScmConfigs.length == 0) {
      return null;
    } else {
      return WorkspaceScmConfigs[0];
    }
  }

  /**
   * Query Data
   *
   * @param queryBean
   * @return WorkspaceScmConfig[]
   * @throws Exception
   */
  public WorkspaceScmConfig[] query(WorkspaceScmConfigDAOQueryBean queryBean) throws Exception {

    List result = super.doQuery(queryBean, new JdbcWorkspaceScmConfigRowMapper());

    return (WorkspaceScmConfig[]) result.toArray(new WorkspaceScmConfig[result.size()]);
  }

  /**
   * Query ${businessObject.name} Selective
   *
   * @param queryBean
   * @return Map[]
   * @model
   * @throws Exception
   */
  public Map<String, Object>[] querySelective(WorkspaceScmConfigDAOQueryBean queryBean)
      throws Exception {

    if (queryBean.getSelectProperties().isEmpty()) {
      queryBean.addAllSelectProperties();
    }

    return super.doQuerySelective(queryBean);
  }

  /**
   * Query Data Count
   *
   * @param queryBean
   * @return int
   * @throws Exception
   */
  public int queryCount(WorkspaceScmConfigDAOQueryBean queryBean) throws Exception {

    return super.doQueryCount(queryBean);
  }

  public void synchronize(
      WorkspaceScmConfig[] aWorkspaceScmConfigs, WorkspaceScmConfigDAOQueryBean queryBean)
      throws Exception {
    daoHelper.synchronize(aWorkspaceScmConfigs, queryBean);
  }

  public void synchronize(
      WorkspaceScmConfig[] aWorkspaceScmConfigs,
      WorkspaceScmConfigDAOQueryBean queryBean,
      net.dao.IDataAccessInterface.ISynchronizeCallback<WorkspaceScmConfig> callBack)
      throws Exception {
    daoHelper.synchronize(aWorkspaceScmConfigs, queryBean, callBack);
  }

  public static class JdbcWorkspaceScmConfigRowMapper implements RowMapper<WorkspaceScmConfig> {

    public WorkspaceScmConfig mapRow(ResultSet resultSet, int arg1) throws SQLException {
      WorkspaceScmConfig object = new WorkspaceScmConfig();

      int columnIndex = 1;

      int __dataType;

      try {

        Object id = null;

        id = resultSet.getObject(columnIndex++);

        object.setIdNull(resultSet.getBoolean(columnIndex++));

        if (id != null) {

          setBeanValue(object, _DataObjectProperty.Id, id);
        }

        Object workspaceId = null;

        workspaceId = resultSet.getObject(columnIndex++);

        object.setWorkspaceIdNull(resultSet.getBoolean(columnIndex++));

        if (workspaceId != null) {

          setBeanValue(object, _DataObjectProperty.WorkspaceId, workspaceId);
        }

        Object scmType = null;

        scmType = resultSet.getObject(columnIndex++);

        object.setScmTypeNull(resultSet.getBoolean(columnIndex++));

        if (scmType != null) {

          setBeanValue(object, _DataObjectProperty.ScmType, scmType);
        }

        Object protocol = null;

        protocol = resultSet.getObject(columnIndex++);

        object.setProtocolNull(resultSet.getBoolean(columnIndex++));

        if (protocol != null) {

          setBeanValue(object, _DataObjectProperty.Protocol, protocol);
        }

        Object hostName = null;

        hostName = resultSet.getObject(columnIndex++);

        object.setHostNameNull(resultSet.getBoolean(columnIndex++));

        if (hostName != null) {

          setBeanValue(object, _DataObjectProperty.HostName, hostName);
        }

        Object hostPort = null;

        hostPort = resultSet.getObject(columnIndex++);

        object.setHostPortNull(resultSet.getBoolean(columnIndex++));

        if (hostPort != null) {

          setBeanValue(object, _DataObjectProperty.HostPort, hostPort);
        }

        Object module = null;

        module = resultSet.getObject(columnIndex++);

        object.setModuleNull(resultSet.getBoolean(columnIndex++));

        if (module != null) {

          setBeanValue(object, _DataObjectProperty.Module, module);
        }

        Object scmUser = null;

        scmUser = resultSet.getObject(columnIndex++);

        object.setScmUserNull(resultSet.getBoolean(columnIndex++));

        if (scmUser != null) {

          setBeanValue(object, _DataObjectProperty.ScmUser, scmUser);
        }

        Object scmPassword = null;

        scmPassword = resultSet.getObject(columnIndex++);

        object.setScmPasswordNull(resultSet.getBoolean(columnIndex++));

        if (scmPassword != null) {

          setBeanValue(object, _DataObjectProperty.ScmPassword, scmPassword);
        }

        Object status = null;

        status = resultSet.getObject(columnIndex++);

        object.setStatusNull(resultSet.getBoolean(columnIndex++));

        if (status != null) {

          setBeanValue(object, _DataObjectProperty.Status, status);
        }

        Object remarks = null;

        remarks = resultSet.getObject(columnIndex++);

        object.setRemarksNull(resultSet.getBoolean(columnIndex++));

        if (remarks != null) {

          setBeanValue(object, _DataObjectProperty.Remarks, remarks);
        }

        Object branch = null;

        branch = resultSet.getObject(columnIndex++);

        object.setBranchNull(resultSet.getBoolean(columnIndex++));

        if (branch != null) {

          setBeanValue(object, _DataObjectProperty.Branch, branch);
        }

        Object label = null;

        label = resultSet.getObject(columnIndex++);

        object.setLabelNull(resultSet.getBoolean(columnIndex++));

        if (label != null) {

          setBeanValue(object, _DataObjectProperty.Label, label);
        }

        return object;
      } catch (Exception e) {
        throw new SQLException(e.getMessage());
      }
    }
  }
}
